<template>
  <div>
    <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="账号" prop="uId">
        <el-input v-model="ruleForm.uId" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input type="password" v-model.number="ruleForm.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="login()">登录</el-button>

      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {isNunm, notNullVerify} from '../utils/validate'

export default {
  data() {
    return {
      ruleForm: {
        uId: '',
        password: ''
      },
      rules: {
        uId: [
          { validator: isNunm, trigger: 'blur' }
        ],
        password: [
          { validator: notNullVerify, trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    login(){
      this.$axios.post("user/teacherLogin",this.$qs.stringify(this.ruleForm))
          .then(resp=>{
            let res = resp.data
            if(res.responseCode == 201){
              //  登录成功
              this.$sessionSet(res.data)
              this.$router.push({
                path:'/home',
              })
            }else{
              //  登录失败
              this.$message.error(res.message);
            }

          })
          .catch(error=>{
            alert("登录失败")
            console.log(error)
          })
    }
  }
}
</script>

<style scoped lang='less'>

</style>